package com.yuetong.employee.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.employee.domain.YtEmployeeBasicInfo;
import com.yuetong.employee.service.IYtEmployeeBasicInfoService;
import com.yuetong.common.utils.poi.ExcelUtil;
import com.yuetong.common.core.page.TableDataInfo;

/**
 * 职工基本信息Controller
 * 
 * @author  卓晓君
 * @date 2025-04-24
 */
@RestController
@RequestMapping("/employee/basicInfo")
public class YtEmployeeBasicInfoController extends BaseController
{
    @Autowired
    private IYtEmployeeBasicInfoService ytEmployeeBasicInfoService;

    /**
     * 查询职工基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('employee:basicInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(YtEmployeeBasicInfo ytEmployeeBasicInfo)
    {
        startPage();
        List<YtEmployeeBasicInfo> list = ytEmployeeBasicInfoService.selectYtEmployeeBasicInfoList(ytEmployeeBasicInfo);
        return getDataTable(list);
    }

    /**
     * 导出职工基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('employee:basicInfo:export')")
    @Log(title = "职工基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtEmployeeBasicInfo ytEmployeeBasicInfo)
    {
        List<YtEmployeeBasicInfo> list = ytEmployeeBasicInfoService.selectYtEmployeeBasicInfoList(ytEmployeeBasicInfo);
        ExcelUtil<YtEmployeeBasicInfo> util = new ExcelUtil<YtEmployeeBasicInfo>(YtEmployeeBasicInfo.class);
        util.exportExcel(response, list, "职工基本信息数据");
    }

    /**
     * 获取职工基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('employee:basicInfo:query')")
    @GetMapping(value = "/{employeeId}")
    public AjaxResult getInfo(@PathVariable("employeeId") Long employeeId)
    {
        return success(ytEmployeeBasicInfoService.selectYtEmployeeBasicInfoByEmployeeId(employeeId));
    }
    /**
     * 获取职工基本信息详细信息通过userId
     */
    @PreAuthorize("@ss.hasPermi('employee:basicInfo:query')")
    @GetMapping(value = "/byUserId/{userId}")
    public AjaxResult getBasicInfoByUserId(@PathVariable("userId") Long userId)
    {
        return success(ytEmployeeBasicInfoService.selectYtEmployeeBasicInfoByUserId(userId));
    }
    /**
     * 新增职工基本信息
     */
    @PreAuthorize("@ss.hasPermi('employee:basicInfo:add')")
    @Log(title = "职工基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtEmployeeBasicInfo ytEmployeeBasicInfo)
    {
        return toAjax(ytEmployeeBasicInfoService.insertYtEmployeeBasicInfo(ytEmployeeBasicInfo));
    }

    /**
     * 修改职工基本信息
     */
    @PreAuthorize("@ss.hasPermi('employee:basicInfo:edit')")
    @Log(title = "职工基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtEmployeeBasicInfo ytEmployeeBasicInfo)
    {
        return toAjax(ytEmployeeBasicInfoService.updateYtEmployeeBasicInfo(ytEmployeeBasicInfo));
    }

    /**
     * 删除职工基本信息
     */
    @PreAuthorize("@ss.hasPermi('employee:basicInfo:remove')")
    @Log(title = "职工基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{employeeIds}")
    public AjaxResult remove(@PathVariable Long[] employeeIds)
    {
        return toAjax(ytEmployeeBasicInfoService.deleteYtEmployeeBasicInfoByEmployeeIds(employeeIds));
    }
}
